#include "../BST/BST.hpp"

/* ideal balanced condtion */
#define Balanced(x) (stature((x).lc) == stature((x).rc))
/**
 * @brief calculate balanced factor
 * 
 */
#define BalFac(x) (stature((x).lc) - stature((x).rc))
/* AVL balanced condition */
#define AvlBalanced(x) ((-2 < BalFac(x)) && (BalFac(x) < 2))

/* choose a higher subtree */
#define tallerChild(p) ( \
	stature((p)->lc) > stature((p)->rc) ? (p)->lc : \
	(stature((p)->lc) < stature((p)->rc) ? (p)->rc : \
	(IsLChild((*p)) ? (p)->lc : (p)->rc)) \
)

template <class T>
class AVL : public BST<T> {
public:
	BinNodePosi(T) insert(const T &e);
	bool remove(const T &e);
};

#include "AVL_implement.hpp"